/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Base;

import Negocio.Persona;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author Alina
 */
public class TelefonoDB {
    
   public boolean grabarTelefono(String telefono) throws SQLException {
        DatabaseManager db = new DatabaseManager();
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        boolean resultado = stmt.execute("INSERT INTO TELEFONO VALUES ('" + telefono + "')");
        var.commit();
        db.getConnection().close();
        return resultado;
    }


    public ArrayList<String> buscarTelefonos(String cedula) throws SQLException {
        DatabaseManager db = new DatabaseManager();
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        ResultSet resultado = stmt.executeQuery("SELECT NUMERO FROM TELEFONO_PERSONA WHERE CEDULA='"+cedula+"'");
        ArrayList todos = new ArrayList();
        while (resultado.next())
        {
            todos.add(resultado.getString("NUMERO"));
        }
        
        db.getConnection().close();
        return todos;
    }

    public boolean eliminarTelefonoPersona(String cedula) throws SQLException {
        DatabaseManager db = new DatabaseManager();
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        System.out.println(cedula);
        String consulta="DELETE TELEFONO_PERSONA WHERE CEDULA='" + cedula + "'";
        boolean resultado = stmt.execute(consulta);

        var.commit();
        db.getConnection().close();
        return resultado;
    }

    public boolean buscarTelefono(String telefono) throws SQLException {
                
        DatabaseManager db = new DatabaseManager();
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        String consulta="SELECT * FROM TELEFONO WHERE NUMERO='" + telefono + "'";
        ResultSet resultado = stmt.executeQuery(consulta);
        
        while(resultado.next())
        {
            db.getConnection().close();
            return true;
        }

        return false;
    }
}
